VERSION 5.00
Begin VB.UserControl HSplitPane 
   Alignable       =   -1  'True
   BackColor       =   &H8000000A&
   ClientHeight    =   6435
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   5385
   ControlContainer=   -1  'True
   ScaleHeight     =   6435
   ScaleWidth      =   5385
   ToolboxBitmap   =   "HSplitPane.ctx":0000
   Begin VB.PictureBox shadow 
      BackColor       =   &H00808080&
      BorderStyle     =   0  'None
      Height          =   1395
      Left            =   1800
      ScaleHeight     =   1395
      ScaleWidth      =   75
      TabIndex        =   1
      Top             =   2460
      Visible         =   0   'False
      Width           =   75
   End
   Begin VB.PictureBox bar 
      BackColor       =   &H00E2A981&
      BorderStyle     =   0  'None
      Height          =   1395
      Left            =   1800
      MouseIcon       =   "HSplitPane.ctx":00FA
      MousePointer    =   99  'Custom
      ScaleHeight     =   1395
      ScaleWidth      =   75
      TabIndex        =   0
      Top             =   720
      Width           =   75
   End
End
Attribute VB_Name = "HSplitPane"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Const DEFAULT_BAR_WIDTH As Single = 75
Const dSplitterPosition As Single = 1800
Const MIN_WIDTH As Single = 75

Dim LeftPane()     As Object
Attribute LeftPane.VB_VarHelpID = -1
Dim RightPane()    As Object
Attribute RightPane.VB_VarHelpID = -1
Dim leftCount       As Long
Dim rightCount      As Long

Dim cx As Single

Dim mSplitterPosition   As Single
Dim mMinWidth           As Single
Dim mRightMin           As Single
Dim mLeftMin            As Single
Dim mAutoResize         As Boolean

Public Sub SetLeft(ParamArray ctls())
    Dim i As Long

    ReDim LeftPane(0 To UBound(ctls)) As Object
    For i = 0 To UBound(ctls)
        Set LeftPane(i) = ctls(i)
    Next
    
    leftCount = i
    LeftPane(0).ZOrder 1

    shadow.ZOrder 0
    DoLayout
End Sub

Public Sub SetRight(ParamArray ctls())
    Dim i As Long
    
    ReDim RightPane(0 To UBound(ctls)) As Object
    For i = 0 To UBound(ctls)
        Set RightPane(i) = ctls(i)
        
    Next
    
    rightCount = i
    RightPane(0).ZOrder 1
    
    shadow.ZOrder 0
    DoLayout
End Sub

Private Sub bar_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    shadow.Left = bar.Left
    shadow.Visible = True
    cx = bar.Left
End Sub

Private Sub bar_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If shadow.Visible Then
        If cx + x <= mLeftMin Then
            shadow.Move mLeftMin
        ElseIf cx + x >= ScaleWidth - bar.Width - mRightMin Then
            shadow.Move ScaleWidth - bar.Width - mRightMin
        Else
            shadow.Move cx + x
        End If
    End If
End Sub

Private Sub bar_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    bar.Left = shadow.Left
    shadow.Visible = False
    mSplitterPosition = bar.Left
    DoLayout
End Sub

Private Sub UserControl_InitProperties()
    mSplitterPosition = dSplitterPosition
    mAutoResize = False
    shadow.Width = DEFAULT_BAR_WIDTH
    bar.Width = DEFAULT_BAR_WIDTH
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    mMinWidth = PropBag.ReadProperty("MinWidth", MIN_WIDTH)
    mSplitterPosition = PropBag.ReadProperty("SplitterPosition", dSplitterPosition)
    mLeftMin = PropBag.ReadProperty("LeftMin", 0)
    mRightMin = PropBag.ReadProperty("RightMin", 0)
    mAutoResize = PropBag.ReadProperty("AutoResize", False)
    bar.BackColor = PropBag.ReadProperty("BarColor", bar.BackColor)
    BackColor = PropBag.ReadProperty("BackColor", UserControl.BackColor)
    bar.Width = PropBag.ReadProperty("BarWidth", DEFAULT_BAR_WIDTH)
    shadow.Width = bar.Width
    UserControl_Resize
End Sub


Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "MinWidth", mMinWidth, MIN_WIDTH
    PropBag.WriteProperty "SplitterPosition", mSplitterPosition, dSplitterPosition
    PropBag.WriteProperty "LeftMin", mLeftMin, False
    PropBag.WriteProperty "RightMin", mRightMin, False
    PropBag.WriteProperty "AutoResize", mAutoResize, False
    PropBag.WriteProperty "BarWidth", shadow.Width, DEFAULT_BAR_WIDTH
    PropBag.WriteProperty "BarColor", bar.BackColor
    PropBag.WriteProperty "BackColor", UserControl.BackColor
End Sub

Private Sub UserControl_Resize()
    bar.Move mSplitterPosition, 0, bar.Width, ScaleHeight
    
    shadow.Move bar.Left, 0, shadow.Width, ScaleHeight
    DoLayout
End Sub

Public Property Get SplitterPosition() As Single
    SplitterPosition = mSplitterPosition
End Property

Public Property Let SplitterPosition(ByVal Value As Single)
    mSplitterPosition = Value
    UserControl_Resize
End Property

Public Property Get AutoResize() As Boolean
    AutoResize = mAutoResize
End Property

Public Property Let AutoResize(ByVal Value As Boolean)
    mAutoResize = Value
    UserControl_Resize
End Property

Public Property Get BarWidth() As Single
    BarWidth = shadow.Width
End Property

Public Property Let BarWidth(ByVal Value As Single)
    bar.Width = Value
    shadow.Width = Value
    DoLayout
End Property

Public Property Get MinWidth() As Single
    MinWidth = mMinWidth
End Property

Public Property Let MinWidth(ByVal Value As Single)
    mMinWidth = Value
    DoLayout
End Property

Public Property Let BarColor(ByVal Value As OLE_COLOR)
    bar.BackColor = Value
End Property

Public Property Get BarColor() As OLE_COLOR
    BarColor = bar.BackColor
End Property

Public Property Get BackColor() As OLE_COLOR
    BackColor = UserControl.BackColor
End Property

Public Property Let BackColor(ByVal Value As OLE_COLOR)
    UserControl.BackColor = Value
End Property

Public Property Let LeftMin(ByVal Value As Single)
    mLeftMin = Value
End Property

Public Property Get LeftMin() As Single
    LeftMin = mLeftMin
End Property

Public Property Get RightMin() As Single
    RightMin = mRightMin
End Property

Public Property Let RightMin(ByVal Value As Single)
    mRightMin = Value
End Property

Private Sub DoLayout()
On Error Resume Next
    Dim i As Long
    If leftCount = 0 Or rightCount = 0 Then Exit Sub
    
    For i = 0 To leftCount - 1
        LeftPane(i).Move 0, 0, bar.Left, ScaleHeight
    Next
    
    For i = 0 To rightCount - 1
        RightPane(i).Move bar.Left + bar.Width, 0, ScaleWidth - bar.Left - bar.Width, ScaleHeight
    Next
    
End Sub


